package com.example.mydianping.controller;

import com.example.mydianping.dto.Result;
import com.example.mydianping.pojo.Voucher;
import com.example.mydianping.service.VoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/voucher")
public class VoucherController {

    @Resource
    private VoucherService voucherService;

    //查询店铺优惠卷列表
    @GetMapping("/list/{shopId}")
    public Result shopVoucherList(@PathVariable("shopId") Long shopId){
        List<Voucher> list = voucherService.queryVoucherList(shopId);
        return Result.ok(list);
    }

    //新增普通卷
    @PostMapping
    public Result addVoucher(@RequestBody Voucher voucher){
        voucherService.add(voucher);
        return Result.ok(voucher.getId());
    }

    //新增优惠卷
    @PostMapping("/seckill")
    public Result addSecKillVoucher(@RequestBody Voucher voucher){
        voucherService.addSecKill(voucher);
        return Result.ok(voucher.getId());
    }
}
